package com.example.demo.service;

import com.example.demo.entity.Instrument;
import com.example.demo.mapper.InstrumentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InstrumentImpl implements InstrumentService {

    @Autowired
    private InstrumentMapper instrumentMapper;

    @Override
    public void addInstrument(Instrument instrument) {
        instrumentMapper.insertInstrument(instrument);
    }

    @Override
    public void updateInstrument(Instrument instrument) {
        instrumentMapper.updateInstrument(instrument);
    }

    @Override
    public void deleteInstrument(Integer instrumentId) {
        instrumentMapper.deleteInstrument(instrumentId);
    }

    @Override
    public Instrument getInstrumentById(Integer instrumentId) {
        return instrumentMapper.selectInstrumentById(instrumentId);
    }

    @Override
    public List<Instrument> getAllInstruments() {

        return instrumentMapper.selectAllInstruments();
    }

    @Override
    public List<Instrument> searchInstruments(String name) {
        return instrumentMapper.searchInstruments(name);
    }

    @Override
    public List<Instrument> getHotInstruments() {
        return instrumentMapper.findHotInstruments(); // 从数据库中获取按播放次数排序的乐器列表
    }

    // 增加浏览量
    @Override
    public void incrementViewCount(Integer id) {
        instrumentMapper.incrementViewCount(id);
    }
}
